home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
-
- //
- // Safe way to add menu items from a plug-in. This method will test if
- // the menu is already built or not, and either create the item right
- // away, or add the command to the menu construction callback.
- //
- // $mainMenu is one of the top level menus.
- // $cmd is the mel script to be executed to build the item. It must
- // return the mel procedure to remove the added items.
- // $globVarName must be a global variable name, variable must be
- // initialized to "". This variable is used to keep track of the
- // built or registered menus.
- //
- // Example:
- // global string $myGlobVariable = "";
- // global string $gModelingMenus[];
- // string $menu = $gModelingMenus[4]; // Edit polygon menu
- // addMenuItemSafe($menu, "addMyItem", "myGlobVariable");
- //
- // global proc string addMyItem()
- // {
- // menuItem...;
- // return "deleteUI ...";
- // }
- //
- ///////////////////////////////////////////////////////////////////////////////
- global proc addMenuItemSafe(string $mainMenu, string $cmd, string $globVarName)
- {
- // Get the variable value
- string $tmp = "global string $"+$globVarName+
- ";string $temporary = $" + $globVarName;
- string $val = eval($tmp);
-
- // Make sure menu was not already dealt with...
- if ($val != "")
- return;
-
- string $tmp = ";global string $"+$globVarName+
- "; if (($"+$globVarName+" == \"\") || ($"+
- $globVarName+" == \"CB:\")) {$"+$globVarName+" = `"+$cmd+"`;}";
-
- if (`menu -q -ni $mainMenu`) // Add a new entry to the menu
- eval ($tmp);
- else
- {
- // Otherwise, we have to add a call back to the menu.
- string $buildMethod = `menu -q -pmc $mainMenu`;
- menu -e -pmc ($buildMethod + $tmp) $mainMenu;
- string $tmp2 = "global string $"+$globVarName+
- ";$"+$globVarName+" = \"CB:\"";
- eval ($tmp2);
- }
- return;
- }
-
- //
- // Remove menu items created with addMenuItemSafe.
- // $mainMenu and $globVarName arguments must be the same as for
- // addMenuItemSafe.
- //
- ///////////////////////////////////////////////////////////////////////////////
- global proc removeMenuItemSafe(string $mainMenu, string $globVarName)
- {
- string $tmp = "global string $" + $globVarName +
- ";string $temporary = $" + $globVarName;
- string $val = eval($tmp);
-
- if ($val != "")
- {
- // Remove the callback if it was added.
- string $buildMethod = `menu -q -pmc $mainMenu`;
- $buildMethod = `substitute (";global string \$"+$globVarName+".*`;}")
- $buildMethod ""`;
- menu -e -pmc $buildMethod $mainMenu;
-
- if ($val != "CB:") // The menu was built, remove it.
- eval $val;
-
- $tmp = "global string $"+$globVarName+ ";$"+$globVarName+" = \"\"";
- eval ($tmp);
- }
- }
-